package edu.info.manager.service;

import edu.info.manager.dao.TeacherDao;
import edu.info.manager.domain.Teacher;

public class TeacherService {
    private TeacherDao teacherDao = new TeacherDao();
    public boolean addTeacher(Teacher teacher) {
        return teacherDao.addTeacher(teacher);
    }

    public Teacher[] findAllTeacers() {
        Teacher[] teas = teacherDao.findAllTeachers();

        boolean flag = false;
        for (int i = 0; i < teas.length; i++) {
            if(teas[i] != null){
                flag = true;
                break;
            }
        }

        if(flag){
            return teas;
        }else{
            return null;
        }
    }

    public boolean isExist(String id) {
        Teacher[] allTeachers = teacherDao.findAllTeachers();
        boolean flag = false;
        for (int i = 0; i < allTeachers.length; i++) {
            Teacher tea = allTeachers[i];
            if(tea != null && tea.getId().equals(id)){
                flag = true;
                break;
            }
        }
        return flag;
    }

    public void deleteTeacherById(String id) {
        teacherDao.deleteTeacherById(id);
    }

    public void updateTeacherById(String id, Teacher teacher) {
        teacherDao.updateTeacherById(id,teacher);
    }
}
